#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,T;
int a[200005];
int f[200005][2][2];
int ans;
int read(){
	int a;
	scanf("%lld",&a);
	return a;
}

void dfs(int x,int r,int b,int tot){
//	cout << x + 1 << " " << r << " " << b << " " << tot << endl;
	if(x == n + 1){
		if(tot > ans)
			ans = tot;
		return;
	}
	else{
		if(a[x] == r){
			dfs(x+1,a[x],b,tot+a[x]);
		}
		if(a[x] == b){
			dfs(x+1,r,a[x],tot+a[x]);
		}
		else{
			dfs(x+1,a[x],b,tot);
			dfs(x+1,r,a[x],tot);
		}
	}
}


signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin >> T;
	while(T--){
		memset(a,0,sizeof(a));
		n = read();
		for(int i = 1;i <= n;i++)
			a[i] = read();
		dfs(0,-1,-1,0);
		cout << ans << endl;
	}
	return 0;
}
